import request from "@/utils/request";
import type { SysConfigDTO, SysConfigFiltDTO, SysConfigVO } from "./sysConfigType";
import type { IdDTO, PageQueryDTO, PageQueryVO } from "../type/baseType";

enum URL {
    URL_CONFIG_BASE = '/config',
    URL_CONFIG_PAGE = URL_CONFIG_BASE + '/page',
}

/**
 * 增加Config
 * @param sysConfigDTO
 * @returns 
 */
export const addConfig = (sysConfigDTO: SysConfigDTO):
    Promise<undefined> =>
    request.post(URL.URL_CONFIG_BASE, sysConfigDTO)

/**
 * 删除Config
 * @param id
 * @returns 
 */
export const deleteConfig = (id: IdDTO):
    Promise<undefined> =>
    request.delete(`${URL.URL_CONFIG_BASE}/${id.id}`)

/**
 * 修改Config
 * @param id
 * @param sysConfigDTO
 * @returns 
 */
export const updateConfig = (id: IdDTO, sysConfigDTO: SysConfigDTO):
    Promise<undefined> =>
    request.put(`${URL.URL_CONFIG_BASE}/${id.id}`, sysConfigDTO)

/**
 * 分页查询所有Config列表
 * @param pageQueryDTO
 * @returns 
 */
export const queryConfigPage = (pageQueryDTO: PageQueryDTO<SysConfigFiltDTO>):
    Promise<PageQueryVO<SysConfigVO>> =>
    request.get(URL.URL_CONFIG_PAGE, {
        params: {
            pageNum: pageQueryDTO.pageNum,
            pageSize: pageQueryDTO.pageSize,
            ...pageQueryDTO.param
        }
    })

/***
 * 查询所有字典
 */
export const queryConfigAll = ():
    Promise<Record<string, Record<string, string>>> =>
    request.get(URL.URL_CONFIG_MAP)

/**
 * 增加ConfigData
 * @param sysConfigDataDTO
 * @returns 
 */
export const addConfigData = (sysConfigDataDTO: SysConfigDataDTO):
    Promise<undefined> =>
    request.post(URL.URL_CONFIG_DATA_BASE, sysConfigDataDTO)

/**
 * 删除ConfigData
 * @param id
 * @returns 
 */
export const deleteConfigData = (id: IdDTO):
    Promise<undefined> =>
    request.delete(`${URL.URL_CONFIG_DATA_BASE}/${id.id}`)

/**
 * 修改ConfigData
 * @param id
 * @param sysConfigDataDTO
 * @returns 
 */
export const updateConfigData = (id: IdDTO, sysConfigDataDTO: SysConfigDataDTO):
    Promise<undefined> =>
    request.put(`${URL.URL_CONFIG_DATA_BASE}/${id.id}`, sysConfigDataDTO)

/**
 * 分页查询所有ConfigData列表
 * @param pageQueryDTO
 * @param identifier
 * @returns 
 */
export const queryConfigDataPage = (pageQueryDTO: PageQueryDTO<SysConfigDataFiltDTO>, identifier: string):
    Promise<PageQueryVO<SysConfigDataVO>> =>
    request.get(URL.URL_CONFIG_DATA_PAGE, {
        params: {
            pageNum: pageQueryDTO.pageNum,
            pageSize: pageQueryDTO.pageSize,
            identifier,
            ...pageQueryDTO.param
        }
    })